<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<div id="app">
    <p>商品名称：{{name}}</p>
    <p>商品价格：{{price}}</p>
    <p>商品名称和价格： {{namePrice}}</p>
</div>
<!--引入vue文件-->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
    const vm = Vue.createApp({
        data(){
            return {
                name: "洗衣机",
                price: "6800元"
            }
        },
        computed: {
            namePrice: {
                //getter方法，显示时调用
                get:function(){
                    //拼接name和price
                    return this.name + "**" + this.price;
                },
                //setter方法，设置namePrice时调用，其中参数用来接收新设置的值
                set:function(newName){
                    var names = newName.split(" "); //以空格拆分字符串
                    this.name = names[0];
                    this.price = names[1];
                }
            }
        }
    }).mount('#app');
</script>

</body>
</html>
